802G - Fake News (easy) - CodeForces Solution


implementation strings *800

Please click on ads to support us..

Python Code:

a='heidi'
s=input()
j=0
for i in range(len(s)):
    if s[i]==a[j]:
        j+=1 
        if j==5:
            break
if j==5:
    print('YES')
else:
    print('NO')

C++ Code:

#include <bits/stdc++.h>
using namespace std;

int main()
{
    string s;
    cin >> s;
    unordered_map<char,vector<int>>mp;
    for(int i = 0;i < s.length(); i++)
    {
        if(s[i] == 'h' || s[i] == 'e' || s[i] == 'i' || s[i] == 'd')
        {
            mp[s[i]].push_back(i);
        }
    }
    bool isvalid = true;
    if(mp.find('h') == mp.end() || mp.find('e') == mp.end() || mp.find('i') == mp.end() || mp.find('d') == mp.end())
    {
        cout<<"NO"<<endl;
        return 0;
    }
    int ind = mp['h'][0];
    if(lower_bound(mp['e'].begin(),mp['e'].end(),ind) == mp['e'].end())
    {
        cout<<"NO"<<endl;
        return 0;
    }else
    {
        ind = *lower_bound(mp['e'].begin(),mp['e'].end(),ind);
    }
    if(lower_bound(mp['i'].begin(),mp['i'].end(),ind) == mp['i'].end())
    {
        cout<<"NO"<<endl;
        return 0;
    }else
    {
        ind = *lower_bound(mp['i'].begin(),mp['i'].end(),ind);
    }
    if(lower_bound(mp['d'].begin(),mp['d'].end(),ind) == mp['d'].end())
    {
        cout<<"NO"<<endl;
        return 0;
    }else
    {
        ind = *lower_bound(mp['d'].begin(),mp['d'].end(),ind);
    }
    if(lower_bound(mp['i'].begin(),mp['i'].end(),ind) == mp['i'].end())
    {
        cout<<"NO"<<endl;
        return 0;
    }else
    {
        ind = *lower_bound(mp['i'].begin(),mp['i'].end(),ind);
    }
    cout<<"YES"<<endl;
    return 0;
}


Comments

Submit
0 Comments
More Questions

1283B - Candies Division
1451B - Non-Substring Subsequence
1408B - Arrays Sum
1430A - Number of Apartments
1475A - Odd Divisor
1454B - Unique Bid Auction
978C - Letters
501B - Misha and Changing Handles
1496A - Split it
1666L - Labyrinth
1294B - Collecting Packages
1642B - Power Walking
1424M - Ancient Language
600C - Make Palindrome
1669D - Colorful Stamp
1669B - Triple
1669A - Division
1669H - Maximal AND
1669E - 2-Letter Strings
483A - Counterexample
3C - Tic-tac-toe
1669F - Eating Candies
1323B - Count Subrectangles
991C - Candies
1463A - Dungeon
1671D - Insert a Progression
1671A - String Building
1671B - Consecutive Points Segment
1671C - Dolce Vita
1669G - Fall Down